package com.guoyh.baseutils.ext

import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager
import com.google.android.flexbox.JustifyContent

/**
 * @CreateDate: 7/19/21 8:19 PM
 * @Author: guoyh
 * @Description:
 */


fun Context.getLinearManger(isCanSrool : Boolean = true) =
    LinearLayoutManager(this)?.apply {
        isSmoothScrollbarEnabled = isCanSrool
    }

fun Context.getHorLinearLayoutManager() =
    LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)

fun Context.getGridLayoutManager(spanCount: Int) =
    GridLayoutManager(this, spanCount)

fun Context.getHorGridLayoutMagner(spanCount: Int) =
    getGridLayoutManager(spanCount).apply {
        orientation = GridLayoutManager.HORIZONTAL
    }

fun Context.getStaggerGridLayoutManger(spanCount: Int) =
    StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL)


fun Context.getFlexboxLayoutManager() =
    FlexboxLayoutManager(this).apply {
        //flexDirection 属性决定主轴的方向（即项目的排列方向）。类似 LinearLayout 的 vertical 和 horizontal。
        flexDirection = FlexDirection.ROW //主轴为水平方向，起点在左端。
        //flexWrap 默认情况下 Flex 跟 LinearLayout 一样，都是不带换行排列的，但是flexWrap属性可以支持换行排列。
        flexWrap = FlexWrap.WRAP //按正常方向换行
        //justifyContent 属性定义了项目在主轴上的对齐方式。
        justifyContent = JustifyContent.FLEX_START //交叉轴的起点对齐。
    }

